<template>
  <div class="container">
    <baleTable
      :tableData="tableData"
      :tableHead="tableHead"
      :isSearch="true"
      :tableLoading="tableLoading"
      :page="page"
      :isTableRowClick="true"
      @pageSizeChange="pageSizeChange"
      @handleCurrentChange="handleCurrentChange"
      @searchMethods="searchMethods"
      @tableSortChange="tableSortChange"
      @handleRowClick="handleRowClick"
      ref="baleTable"
    >
      <template #headLeft> </template>
      <template #name="{ scope }">
        {{ scope.row.patient.name }}
      </template>

      <template #file="{ scope }">
        <div class="flex-center">
          <tableFile :files="[scope.row.advice_pic]" />
        </div>
      </template>
      <template #status="{ scope }">
        <el-tag type="danger" v-if="scope.row.status==5"> {{ formatterStatus(scope.row.status) }}</el-tag>
         <el-tag type="primary" v-else> {{ formatterStatus(scope.row.status) }}</el-tag>
      
      </template>

      <template #caozuo="{ scope }">
        <div @click.stop="">
          <el-button v-if="scope.row.status=='2'" type="primary" size="mini" @click="reReview(scope.row)"
            >审核</el-button
          >
        </div>
      </template>
    </baleTable>
    <tableDetail ref="tableDetail" />
    <review ref="review" @refresh="getTableData" />
  </div>
</template>

<script>
import tableDetail from "./component/detail.vue";
import { ApigetMDTOrderList } from "@a/index";
import { tableHead } from "./config";
import { mapState, mapGetters } from "vuex";
import tableFile from "@/components/tableFile.vue";
import review from "./component/review.vue";
export default {
  name: "",
  components: { tableFile, tableDetail, review },
  data() {
    return {
      tableHead,
      tableData: [],
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      tableLoading: false,
      searchParams: {},
      sortParams: {},
      editFormVisible: false,
      btnLoading: false,
      order_id: "",
      dialogVisible: false,
      searchOptions: [
        {
          name: "待支付",
          code: "1",
        },
        {
          name: "待审核",
          code: "2",
        },
        {
          name: "进行中",
          code: "3",
        },
        {
          name: "已完成",
          code: "4",
        },
        {
          name: "已取消",
          code: "5",
        },
      ],
    };
  },
  computed: {
    ...mapState(["userState"]),
  },
  created() {
    // 获取传过来的数据，并赋值给本页面中的数据
    if (this.$route.query.order_id) {
      this.order_id = this.$route.query.order_id;
      this.getList();
    }
  },
  mounted() {
    this.getTableData();
  },
  methods: {
    formatterStatus(val) {
      let data = this.searchOptions.find((item) => {
        if (item.code == val) {
          return item;
        }
      });
      if (data) {
        return data.name;
      } else {
        return val;
      }
    },
    refresh() {
      this.getTableData();
    },
    reReview(row) {
      this.$refs.review.show(row);
    },

    handleClose() {
      this.dialogVisible = false;
    },
    getTableData(params = {}) {
      let postParams = {
        ...params,
        ...this.searchParams,
        ...this.sortParams,
        ...this.page,
      };
      if (this.order_id) {
        postParams.order_id = this.order_id;
      }
      this.tableLoading = true;
      ApigetMDTOrderList(postParams).then((res) => {
        let { data, page } = res;
        this.tableData = data;
        this.page.total = page.total;

        this.tableLoading = false;
      });
    },
    dispensing() {
      this.$confirm("是否确认客户到达现场并发药?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {})
        .catch((err) => {});
    },
    searchMethods(params) {
      this.searchParams = {};
      this.page.page = 1;
      this.searchParams = params;
      this.getTableData();
    },
    pageSizeChange(val) {
      this.page.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTableData();
    },
    tableSortChange(params) {
      if (params.sort_str) {
        this.sortParams = { ...this.sortParams, ...params };
      } else {
        delete this.sortParams.sort_str;
        delete this.sortParams.sort_order;
      }
      this.page.page = 1;
      this.getTableData();
    },
    handleRowClick(row) {
      console.log(row);
      this.$refs.tableDetail.show(row.row);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-dialog {
  max-height: 90vh;
}
</style>
